package com.itheima.manager;

import com.itheima.domain.HomeBrand;
import com.itheima.service.SmsHomeBrandService;
import com.itheima.util.Result;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SmsHomeBrandManager {

    @DubboReference
    SmsHomeBrandService smsHomeBrandService;

    //分页查询推荐品牌
    public Result list(Integer pageNum, Integer pageSize, String brandName, Integer recommendStatus) {
        PageBeanVo pageBeanVo = smsHomeBrandService.list(pageNum, pageSize, brandName, recommendStatus);
        return new Result(true, 200, "操作成功", pageBeanVo);
    }

    //添加首页推荐品牌
    public Result create(List<HomeBrand> homeBrandList) {
        for (HomeBrand homeBrand : homeBrandList) {
            smsHomeBrandService.create(homeBrand);
        }
        return new Result(true, 200, "操作成功", 1);
    }

    //批量删除推荐品牌
    public Result delete(List<Long> ids) {
        for (Long id : ids) {
            smsHomeBrandService.delete(id);
        }
        return new Result(true, 200, "操作成功", 1);
    }

    //修改推荐品牌排序
    public Result updateSort(Long id, Integer sort) {

        List<HomeBrand> smsHomeBrands = smsHomeBrandService.smsHomeBrands();
        for (HomeBrand smsHomeBrand : smsHomeBrands) {
            if (smsHomeBrand.getSort() == sort) {
                return new Result(false, 403, "操作失败,排序已存在", 1);
            }
        }
        smsHomeBrandService.updateSort(id, sort);
        return new Result(true, 200, "操作成功", 1);
    }

    //批量修改推荐品牌状态
    public Result updateRecommendStatus(List<Long> ids, Integer recommendStatus) {

        for (Long id : ids) {
            smsHomeBrandService.updateRecommendStatus(id, recommendStatus);
        }
        return new Result(true, 200, "操作成功", 1);
    }
}

